package minijvm.constant;

/**
 * @author ChangLiang
 * @date 2020/4/12
 */
public class NameAndTypeInfo extends ConstantInfo {

    public  int type = ConstantInfo.NAME_AND_TYPE_INFO;

    private int index1;
    private int index2;

    public NameAndTypeInfo(ConstantPool pool) {
        super(pool);
    }

    @Override
    public void accept(Visitor visitor) {
        visitor.visitNameAndType(this);
    }

    public int getIndex1() {
        return index1;
    }
    public void setIndex1(int index1) {
        this.index1 = index1;
    }
    public int getIndex2() {
        return index2;
    }
    public void setIndex2(int index2) {
        this.index2 = index2;
    }

    public String getName(){
        ConstantPool pool = this.getConstantPool();
        UTF8Info utf8Info1 = (UTF8Info)pool.getConstantInfo(index1);
        return utf8Info1.getValue();
    }

    public String getTypeInfo(){
        ConstantPool pool = this.getConstantPool();
        UTF8Info utf8Info2 = (UTF8Info)pool.getConstantInfo(index2);
        return utf8Info2.getValue();
    }

    @Override
    public String toString(){
        return "(" + getName() + "," + getTypeInfo()+")";
    }
}
